const arr = ['/api/login', '/api/register']
const jwt = require('jsonwebtoken')

module.exports = (options, app) => {
  return async (ctx, next) => {
    if (arr.includes(ctx.path)) {
      await next() // 
    } else {
      const { authorization } = ctx.request.headers;
      console.log('authorization: -----', authorization)
      // try {
      //   const user = jwt.verify(authorization, app.config.keys)
      //   console.log(user, 'user-----user')
      //   // 登陆的时候把用户数据保存在了命名空间
      //   // ctx.state.user = user; // userid
        await next()
      // } catch (e) {
      //   ctx.body = {
      //     code: -1,
      //     msg: e.name
      //   }
      // }
    }
  }
}